package com.chaoli.reggie_diy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaoli.reggie_diy.common.BaseContext;
import com.chaoli.reggie_diy.common.R;
import com.chaoli.reggie_diy.domain.Orders;
import com.chaoli.reggie_diy.dto.OrdersDto;
import com.chaoli.reggie_diy.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据={}", orders);
        orderService.submit(orders);
        return R.success("下单成功！！");

    }

    /**
     * 后台查看订单明细
     *
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page<Orders>> ordersPage(int page, int pageSize, String number, String beginTime, String endTime) {
        return orderService.ordersPage(page, pageSize, number, beginTime, endTime);

    }

    /**
     * 用户查看自己订单数据
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<OrdersDto>> userPage(int page, int pageSize) {
        return orderService.userPage(page, pageSize);
    }

    /**
     * 再来一单
     * @param map
     * @return
     */
    @GetMapping("/again")
    public R<String> again(@RequestBody Map<String,String> map){
        return null;
    }

}
